// packageC/pages/productAnswerReply/productAnswerReply.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        picPath: app.globalData.path,
        proInfo: '',
        answer: '',
        reply: ''
    },


    replyInput(e) {
        this.setData({
            reply: e.detail.value
        })
    },
    sendHandle() {
        if (this.data.reply == '') {
            wx.showToast({
                title: '请输入回答内容',
                icon: 'none'
            })
            return
        }
        wx.showLoading({
            title: '',
        })
        var that = this
        var url = app.globalData.url + "product/addAnswer",
            data = {
                userId: app.globalData.userId,
                productId: that.data.proInfo.productId,
                parentId: that.data.answer.answerId,
                answerContent: that.data.reply,
                answerStatus: 1
            };
        app.wxRequest(url, data, res => {
            wx.hideLoading()
            if (res.flag) {
                wx.showModal({
                    title: '提示',
                    content: '发布成功',
                    showCancel: false,
                    complete: (res) => {
                        if (res.confirm) {
                            wx.navigateBack()
                        }
                    }
                })
            } else {
                wx.showToast({
                    title: '发布失败，请重试',
                    icon: 'none'
                })
            }
        })
    },

    imgErrHandleAnswer() {
        var obj = this.data.answer
        obj.isError = true
        this.setData({
            answer: obj
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options);
        var answer = JSON.parse(options.str)
        answer.isError = false
        answer.errorimg = '/img/avatar.png'
        this.setData({
            proInfo: JSON.parse(options.pro),
            answer: answer,
        })
        console.log(this.data);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})